﻿Public Class tbHoaDon
    Private _MaHoaDon As String
    Property MaHoaDon As String
        Get
            Return Me.NgayLap.ToString("MM/yy") + "/" + Me.SoHoaDon.ToString.PadLeft(My.Settings.SoSoKhongHoaDon, "0")
        End Get
        Set(value As String)
            _MaHoaDon = value
        End Set
    End Property

    Private _TongTienChuaGiamGia As Decimal
    Public Property TongTienChuaGiamGia() As Decimal
        Get
            Dim tt = dt.tbChiTietHoaDons.Where(Function(s) s.idHoaDon = Me.id).Sum(Function(s) s.SoLuong * s.DonGia * (100 - s.ChietKhau) / 100)
            Return IIf(tt > 0, tt, 0)
        End Get
        Set(ByVal value As Decimal)
            _TongTienChuaGiamGia = value
        End Set
    End Property

    Private _TongTienDaGiamGia As Decimal
    Public Property TongTienDaGiamGia() As Decimal
        Get
            Dim tt = dt.tbChiTietHoaDons.Where(Function(s) s.idHoaDon = Me.id).Sum(Function(s) s.SoLuong * s.DonGia * (100 - s.ChietKhau) / 100) * (100 - Me.ChietKhau) / 100
            Return IIf(tt > 0, tt, 0)
        End Get
        Set(ByVal value As Decimal)
            _TongTienDaGiamGia = value
        End Set
    End Property

    ReadOnly Property TenKhachHang As String
        Get
            Return dt.tbKhachHangs.Where(Function(s) s.id = Me.idKhachHang).Select(Function(s) s.TenKhachHang).First
        End Get
    End Property

    ReadOnly Property TenNhanVien As String
        Get
            Return dt.tbNhanViens.Where(Function(s) s.id = Me.idNhanVien).Select(Function(s) s.TenNhanVien).First()
        End Get
    End Property
End Class
